﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Shell;
using C1.Phone.Imaging;

namespace ControlExplorer.Controls.Imaging
{
    public partial class GifImages
        : UserControl, IExposeApplicationBarItems
    {
        ApplicationBarMenuItem _btnPlayPause = new ApplicationBarMenuItem();
        C1GifImage _gifImage;

        public GifImages()
        {
            InitializeComponent();

            _btnPlayPause.Text = "pause";
            _btnPlayPause.Click += _btnPlayPause_Click;

            _gifImage = new C1GifImage(new Uri("/ControlExplorer" + App.AssemblySuffix + ";component/Resources/c1AnimatedGif.gif", UriKind.Relative));
            image.Source = _gifImage;
        }


        void _btnPlayPause_Click(object sender, EventArgs e)
        {
            IsPlaying = !IsPlaying;
        }

        bool _isPlaying = true;
        public bool IsPlaying
        {
            get { return _isPlaying; }
            set
            {
                if (_isPlaying != value)
                {
                    _isPlaying = value;
                    if (_isPlaying)
                    {
                        _gifImage.Play();
                        _btnPlayPause.Text = "pause";
                    }
                    else
                    {
                        _gifImage.Stop();
                        _btnPlayPause.Text = "play";
                    }
                }
            }
        }

        public IEnumerable<IApplicationBarMenuItem> ApplicationBarItems
        {
            get 
            { 
                yield return _btnPlayPause; 
            }
        }
    }
}
